package org.r.tools.exception;

import cn.hutool.core.util.StrUtil;
import lombok.Getter;
import lombok.Setter;
import org.r.tools.code.ResCode;

@Getter
@Setter
public class BizException extends RuntimeException {

    private String errorCode;
    private String errorMsg;

    private BizException() {
        super();
    }

    /**
     *
     * @param template
     * @param params
     * @return
     */
    public static BizException error(CharSequence template, Object... params){
        BizException e = new BizException();
        e.setErrorMsg(StrUtil.format(template, params));
        e.setErrorCode(ResCode.DEFAULT_ERROR);
        return e;
    }

    public static BizException error(String errorMsg){
        BizException e = new BizException();
        e.setErrorMsg(errorMsg);
        e.setErrorCode(ResCode.DEFAULT_ERROR);
        return e;
    }
    /**
     *
     * @param errorCode
     * @param template
     * @param params
     * @return
     */
    public static BizException error2(String errorCode, CharSequence template, Object... params){
        BizException e = new BizException();
        e.setErrorCode(errorCode);
        e.setErrorMsg(StrUtil.format(template, params));
        return e;
    }
}
